<?php
/**
 * Created by PhpStorm.
 * User: mac
 * Date: 2019-03-03
 * Time: 15:14
 */
use Swoole\Coroutine as co;

$chan = new co\Channel(1);
go(function () use($chan){
    for($i = 0; $i < 10; $i++) {
        co::sleep(1.0);
        $chan->push(['rand' => rand(1000, 9999), 'index' => $i]);
        echo "$i\n";
    }
});

go(function () use ($chan) {
    $i = 0;
    while ($i < 10) {
        $data = $chan->pop();
        var_dump($data);
        $i++;
    }
});

//PHP版本低于5.4要加上这句话，使脚本开始进行事件轮询
swoole_event::wait();